package com.hulman.oms.web;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.YearReport;
import com.hulman.oms.bean.YearReport;
import com.hulman.oms.service.YearReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class YearReportController
{
	@Autowired
	private YearReportService yearReportService;

	@GetMapping("/year-reports/{id}")
	public Result findYearReportById(@PathVariable Integer id)
	{
		YearReport yearReport = yearReportService.findYearReportById(id);
		return new Result(yearReport);
	}

	@GetMapping("/year-reports")
	public Result findYearReports(Integer page, Integer limit, Integer year, Integer createById, String createByName, Integer state)
	{
		Map<String, Object> map = new HashMap<>();
		map.put("page", page);
		map.put("limit", limit);
        map.put("year", year);
        map.put("createById", createById);
        map.put("createByName", createByName);
        map.put("state", state);
		return yearReportService.findYearReportsResult(map);
	}

	@DeleteMapping("/year-reports/{id}")
	public Result deleteYearReportById(@PathVariable Integer id)
	{
		yearReportService.deleteYearReportById(id);
		return Result.SUCCESS;
	}

	@PutMapping("/year-reports")
	public Result saveYearReport(YearReport yearReport)
	{
		yearReportService.saveYearReport(yearReport);
		return Result.SUCCESS;
	}

	@PostMapping("/year-reports/create")
	public Result create(YearReport yearReport) throws IOException
	{
		yearReportService.create(yearReport);
		return Result.SUCCESS;
	}

	@PostMapping("/year-reports/submit")
	public Result submit(Integer id) throws IOException
	{
		yearReportService.submit(id);
		return Result.SUCCESS;
	}

}
